﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MAF.Windows;
using Domain;

namespace WinFormUI
{
    /// <summary>
    /// 主窗体
    /// </summary>
    public partial class MainForm : Form
    {
        NoteListView list =null;
        NoteEditView edit = null;

        /// <summary>
        /// 主窗体，管理整个应用程序的主要界面（控件）
        /// </summary>
        public MainForm()
        {
            InitializeComponent();

            // 创建NoteListView控件
            list = new NoteListView();
            list.Size = this.Size;
            list.Location = Point.Empty;
            list.NewButtonClick += new EventHandler(list_NewButtonClick);
            list.ListItemClick += new EventHandler(list_ListItemClick);
            list.Anchor = AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom | AnchorStyles.Left;
            list.BringToFront();
            Controls.Add(list);

            // 创建NoteEditView控件
            edit = new NoteEditView();
            edit.Size = this.Size;
            edit.Location = Point.Empty;
            edit.SaveButtonClick += new EventHandler(edit_SaveButtonClick);
            edit.DeleteButtonClick += new EventHandler(edit_DeleteButtonClick);
            Controls.Add(edit);
        }

        /// <summary>
        /// 点击保存按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void edit_SaveButtonClick(object sender, EventArgs e)
        {
            list.RefreshList();
            list.BringToFront();
        }

        /// <summary>
        /// 点击删除按钮事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void edit_DeleteButtonClick(object sender, EventArgs e)
        {
            list.RefreshList();
            list.BringToFront();
        }

        /// <summary>
        /// 点击新建按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void list_NewButtonClick(object sender, EventArgs e)
        {
            edit.BringToFront();
            edit.FillData();
        }

        /// <summary>
        /// 点击列表中的项目
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void list_ListItemClick(object sender, EventArgs e)
        {
            var item = sender as MAFListViewItem;
            edit.BringToFront();
            edit.FillData(item.Tag as Note);
        }
    }
}
